<!doctype html>
<html>

<head>
<meta charset="utf-8">
<TITLE>论坛--帖子列表</TITLE>

<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<script type="text/javascript" charset="utf-8" src="ueditor.config.js"></script>
<script type="text/javascript" charset="utf-8" src="ueditor.all.min.js">
	
</script>
<!--建议手动加在语言，避免在ie下有时因为加载语言失败导致编辑器加载失败-->
<!--这里加载的语言文件会覆盖你在配置项目里添加的语言类型，比如你在配置项目里配置的是英文，这里加载的中文，那最后就是中文-->
<script type="text/javascript" charset="utf-8" src="lang/zh-cn/zh-cn.js"></script>

<Link rel="stylesheet" type="text/css" href="css/style.css" />
<style type="text/css">
.send {
	margin-top: 15px;
	margin-left: 560px;
}

.pagediv {
	width: 978px;
	height: 66px;
}

.pagediv  ul {
	width: 400px;
	height: 24px;
	list-style: none;
}

.pagediv  ul li {
	float: left;
}

.pageli1 {
	width: 166.18px;
	height: 24px;
}

.pageli2 {
	width: 45px;
	height: 24px;
}

.pageli3 {
	width: 135px;
	height: 24px;
}

.pageli3 input {
	width: 32px;
	height: 16px;
}
.outlogin{
float: right;
}
</style>
</HEAD>

<BODY>
	<DIV>
		<IMG src="image/logo.gif">
	</DIV>
	<!--      用户信息、登录、注册        -->

	<DIV class="h">
		您尚未 <a href="login.html">登录</a> &nbsp;| &nbsp; <A href="reg.html">注册</A>
		|
	</DIV>

	<!--      主体        -->
	<DIV>
		<!--      导航        -->
		<br />
		<DIV>
			&gt;&gt; <B><a href="index.html">论坛首页</a></B>&gt;&gt;
			<!-- 板块名称   href中应当在其后拼接?板块id=? -->
			<B><a class="boardname" href="list.html"></a></B>
		</DIV>
		<br />
		<!--      新帖        -->
		<DIV>
			<A href="#editor"> <IMG src="image/post.gif" name="td_post"
				border="0" id=td_post>
			</A>
		</DIV>
		<br/>
		<DIV class="t">
			<TABLE cellSpacing="0" cellPadding="0" width="100%">
				<TR>
					<TH class="h" style="WIDTH: 100%" colSpan="5"><SPAN>&nbsp;</SPAN>
					</TH>
				</TR>
				<!--       表 头           -->
				<TR class="tr2">
					<TD>&nbsp;</TD>
					<TD style="WIDTH: 70%" align="center">文章</TD>
					<TD style="WIDTH: 10%" align="center">操作</TD>
					<TD style="WIDTH: 10%" align="center">作者</TD>
					<TD style="WIDTH: 10%" align="center">回复</TD>
				</TR>
				<!--         主 题 列 表        -->

			</TABLE>
		</DIV>
		<!--  翻 页          -->
		<div class="pagediv">
			<ul class="pageul">
				<li class="pageli1"><a class="fristpage"
					href="javascript:void(0)">首页</a> <a class="frontpage"
					href="javascript:void(0)">上一页</a> <a class="nowpage"
					href="javascript:void(0)">1</a> <a class="nextpage"
					href="javascript:void(0)">下一页</a> <a class="lastpage"
					href="javascript:void(0)">尾页</a></li>
				<li class="pageli2"></li>
				<li class="pageli3">，跳到 <input class="jump_input_bright"
					id="jumpPage6" type="text" max-page="2" theme="6" name="inputpa">页&nbsp;
					<button class="btn" type="button" value="确定">确定</button>&nbsp;
				</li>

			</ul>
		</div>


		<!-- 发表新帖 -->
		<div class="new_edit" style="margin-left: 460px;">
			标题：<span id="titleError" style="color: red"></span>
			<p class="title" contenteditable="true"
				style="border: 1px lightskyblue solid; width: 600px; height: 20px;"></p>

			<div>
				<script id="editor" type="text/plain"
					style="width: 600px; height: 200px;"></script>
			</div>
			<button class="send" onclick="send()">发帖</button>
		</div>

	</DIV>

	<!--             声 明          -->
	<BR />
	<CENTER class="gray">©俊泽工作室</CENTER>
</BODY>
<script src="js/jquery.min.js"></script>
<script>
	//实例化编辑器
	//建议使用工厂方法getEditor创建和引用编辑器实例，如果在某个闭包下引用该编辑器，直接调用UE.getEditor('editor')就能拿到相关的实例
	var ue = UE.getEditor('editor');
	
	//得到uid
	var userid;
	
	//得到table的内容
	var str1 = $('.t table').html();

	//将地址栏中的板块名放到板块名称中
	var thisHref = decodeURI(window.location.href);
	var name = thisHref.substring(thisHref.indexOf('=') + 1);
	//得到bid
	var bid=name.substring(name.indexOf('=')+1);
	var bname=name.split("&")[0];
	$('.boardname').html(bname);
	$('.boardname').attr('href',thisHref);
	
	$(function() {
		//页面加载主题
		//显示欢迎信息
		$.post('user.action',{op:'findsession'},function(data){
			if(2==data){
				var str='您尚未　<a href="login.html">登录</a>&nbsp;| &nbsp; <A href="reg.html">注册</A> |';
				$('.h').html(str);
			}else{
				userid=data.u_id;
				var str='欢迎用户：'+data.u_name+'&nbsp;&nbsp;登陆BBS论坛 &nbsp;&nbsp;<a href="MyWeb.html" >个人主页</a><a class="outlogin" href="javascript:outbbs()" >退出BBS论坛</a>';
				$('.h').html(str);
			}
		},'json');
		showpage();

	});
	
	function outbbs(){
		$.post('user.action',{op:'outlogin'},function(data){
			if(1==data){
				window.location.href='login.html';
			}
		});
	}

	function showpage() {
		var nowpa = $('.pagediv .nowpage ').html()
		$.get('topic.action', {
			op : 'find',
			nowpage : nowpa,
			b_id:bid
		}, function(data) {
			showtopic(data);
		}, 'json');

	}

	//显示话题
	function showtopic(arr) {
		var str = '';
		var str2 = '';
		for (var i = 0; i < arr[0].length; i++) {
			//得到数据传来的uid
			var uid = arr[1][i].u_id;
			if (userid !== uid) {
				str2 = '<A class ="delete"  href="javascript:deleteReply('
						+ arr[1][i].t_id + ')"></A>'
			} else if (userid == uid) {
				str2 = '<A class ="delete"  href="javascript:deleteReply('
						+ arr[1][i].t_id + ')">删除     </A>'
			}

			//根据用户的id来判断只显示除自己以外的用户举报按钮
			if (userid != uid) {
				str3 = '<A  calss="Report " href="javascript:impeach(\''
						+ arr[1][i].t_title + '\',\'' + arr[1][i].t_id
						+ '\')">举报</A>';
			} else if (userid == uid) {
				str3 = ''
			}

			str += '<TR class="tr3"><TD><IMG src="image/topic.gif" border=0></TD>'
					+ '<TD style="FONT-SIZE: 15px"><A href="detail.html?'
					+'b_name='
					+bname
					+'&b_id='
					+bid
					+'&t_title='
					+ arr[1][i].t_title
					+ '&t_id='
					+ arr[1][i].t_id
					+ '">'
					+ arr[1][i].t_title
					+ '</A></TD>'
					+ '<TD align="center">'
					+ str2
					+ ''
					+ str3
					+ '</TD>'
					+ '<TD align="center">'
					+ arr[1][i].u_name
					+ '</TD>'
					+ '<TD align="center">'
					+ arr[0][i] + '</TD></TR>';
		}
		$('.t table').html(str1 + str);
		//得到总页数
		if(0==arr[2]){
			var page = '共<span class="red">1</span>页';
		}else{
			var page = '共<span class="red">' + arr[2] + '</span>页';
		}
		
		$('.pagediv .pageul .pageli2').html(page);

	}

	//删除话题信息
	function deleteReply(tid) {
		var r = confirm('请确认，是否删除话题？');
		if (r == true) {
			deleteR(tid);
		} else {
			return;
		}

		function deleteR(tid) {
			$.get('topic.action', {
				op : 'delete',
				t_id : tid
			}, function(data) {
				if (data == 1) {

					alert("删除成功");
					window.location.reload();
				} else if(0==data) {
					alert("删除失败");
				}
			});
		}

	}

	//首页
	$(".pagediv .fristpage").click(function() {
		$('.pagediv .nowpage').html(1);
		showpage();
	});

	// 上一页
	$(".pagediv .frontpage").click(function() {
		var pagenum = $('.pagediv .nowpage').html();
		if (pagenum <= 1) {
			$('.pagediv .nowpage').html(1);
		} else {
			var nowpage = pagenum - 1;
			$('.pagediv .nowpage ').html(nowpage);
		}
		showpage();
	});

	//下一页
	$(".pagediv .nextpage  ").click(function() {
		var pagenum = $('.pagediv .nowpage  ').html();
		var AllpageNum =$('.pagediv .pageli2  .red ').html();
		var nowpage;
		if(pagenum <AllpageNum ){
			 nowpage =parseInt(pagenum)+1;
		}else if(pagenum ==AllpageNum ){
			 nowpage=AllpageNum
		}
		$('.pagediv .nowpage  ').html(nowpage);
		showpage();
	});

	//尾页
	$(".pagediv .lastpage").click(function() {
		var pagenum = $('.pagediv .nowpage  ').html();//现在的页数
		var lastpage = $('.pagediv .pageli2  .red ').html();//最后一页(总页数)
		$(' .pagediv .nowpage  ').html(lastpage);
		showpage();

	});

	//跳转页面
	$(".pagediv  .btn").click(function showtopic(arr) {
		var AllpageNum =$('.pagediv .pageli2  .red ').html();
		var inputpage= $('.pagediv .jump_input_bright' ).val();
		var inputpa=parseInt(inputpage);
	
		if(inputpage >=AllpageNum||inputpage<=0){
			$('.pagediv .jump_input_bright' ).val('');
			alert('请输入正确的页数')
			return;
		}else{
			$(' .pagediv .nowpage  ').html(inputpa);
		}

		showpage();

	});
	
	function impeach(title,tid){
		window.open("impeachtopic.html?t_title="+title+"&t_id="+tid, "newwindow", "height=750px, width=700, top=0, left=0, toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no");
	}

	function send() {
		var str = thisHref.substring(thisHref.indexOf('=') + 1);
		var bid = str.substring(str.indexOf('=') + 1);
		var title = $('.title').html();
		var content = UE.getEditor('editor').getContent();
		if ("" != title && "" != content) {
			$.post('topic.action', {
				op : 'addtopic',
				t_title : title,
				t_content : content,
				b_id : bid
			}, function(data) {
				if (2 == data) {
					var r = confirm('请登录后进行发帖，是否登陆？');
					if (r == true) {
						window.location.href = 'login.html';
					} else {
						return;
					}
				}
				if (1 == data) {
					window.location.reload();
				}
			});
		} else {
			$('#titleError').html('标题或内容不能为空');
		}
	}

	/*
	 function fileChange(){
	 var formData=new FormData($('#addgroup')[0]);
	 //得到选择的文件路径
	 var upload=$('.edit_img').val();
	 //得到文件类型
	 var fileType = upload.substr(upload.length-4,upload.length);
	 formData.append('upload',upload);
	 if('.bmp'==fileType.toLowerCase()||'.gif'==fileType.toLowerCase()||'.jpg'==fileType.toLowerCase()||'.png'==fileType.toLowerCase()){
	 $.ajax({
	 type:'post',
	 url:"fileupload.action?op=addfile",
	 data:formData,
	 cache:false,
	 processData:false,
	 contentType:false,
	 success:function(data){
	 var str=$('.content').html()
	 str+='<img width="50px" height="50px" src='+data+' />';
	 $('.content').html(str);
	 $('#fileTypeError').html('');
	 },
	 error:function(){
	 alert("上传失败");
	 }
	 });
	 }else{
	 $('#fileTypeError').html('文件格式错误，仅允许上传文件格式为bmp、gif、jpg、png的图片');
	 }
	 }*/
</script>
</HTML>